<template>
  <ex-dialog width="800px" class="ex-diolog" :title="title" :visible="visible" :close-on-click-modal="false"
    @closeDialog="handleClose">
    <div class="main" v-loading="loading">
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="140px" class="demo-ruleForm"
        :disabled="disabled">
        <el-row>

          <el-form-item>
            请指定责任成员，将删除成员的客户、服务单的操作责任人移交给他
          </el-form-item>
          <el-col :span="18">
            <el-form-item v-if="clientSelect.length > 0" label="移交客户：" prop="clientId">
              <el-select v-model="ruleForm.clientId" filterable placeholder="请选择" size="small">
                <el-option v-for="item in clientSelect" :key="item.id" :label="item.value" :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item v-if="componentSelect.length > 0" label="移交组品责任：" prop="componentId">
              <el-select v-model="ruleForm.componentId" filterable placeholder="请选择" size="small">
                <el-option v-for="item in componentSelect" :key="item.id" :label="item.value" :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item v-if="scheduleSelect.length > 0" label="移交排期责任：" prop="scheduleId">
              <el-select v-model="ruleForm.scheduleId" filterable placeholder="请选择" size="small">
                <el-option v-for="item in scheduleSelect" :key="item.id" :label="item.value" :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item v-if="serviceSelect.length > 0" label="移交服务责任：" prop="serviceId">
              <el-select v-model="ruleForm.serviceId" filterable placeholder="请选择" size="small">
                <el-option v-for="item in serviceSelect" :key="item.id" :label="item.value" :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item v-if="materielSelect.length > 0" label="移交物料责任：" prop="materielId">
              <el-select v-model="ruleForm.materielId" filterable placeholder="请选择" size="small">
                <el-option v-for="item in materielSelect" :key="item.id" :label="item.value" :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item v-if="centerControlSelect.length > 0" label="移交中控责任：" prop="centerControlId">
              <el-select v-model="ruleForm.centerControlId" filterable placeholder="请选择" size="small">
                <el-option v-for="item in centerControlSelect" :key="item.id" :label="item.value" :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item  v-if="operationControlSelect.length > 0" label="移交运营负责人：" prop="operationControlId">
              <el-select v-model="ruleForm.operationControlId" filterable placeholder="请选择" size="small">
                <el-option v-for="item in operationControlSelect" :key="item.id" :label="item.value" :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

      </el-form>
    </div>
    <div class="button_box">
      <el-button @click="handleClose">取消</el-button>
      <el-button type="primary" :loading="AgreeLoading" @click="submitForm('ruleForm')">确认提交</el-button>
    </div>
  </ex-dialog>
</template>
<script>
import Loading from "@/components/Loading/index";
// api
import {
  deleteResponsible,
  responsibleRemoveDetail,
} from "@/api/customer/principalList";
import '@wangeditor/editor/dist/css/style.css'
import {
  Editor,
  Toolbar
} from "@wangeditor/editor-for-vue";
export default {
  components: {
    Loading,
    Editor,
    Toolbar
  },
  props: {
    visible: Boolean,
    id: String,
    pathType: String,
  },
  data() {
    return {
      labelWidth: "150px",
      inputWidth: "420px",
      title: "删除负责人",
      loading: false,
      disabled: false,
      AgreeLoading: false,
      ruleForm: {
        clientId: '',// 客户id
        componentId: '',//组品id
        scheduleId: '',//排期id
        serviceId: '',  //服务id
        materielId: '',//物料id
        centerControlId:'',//中控id
        operationControlId:'',//运营负责人id
        id: '',
      },
      operationControlSelect:[],//运营负责人列表
      clientSelect: [],
      componentSelect: [],
      scheduleSelect: [],
      serviceSelect: [],
      materielSelect: [],
      centerControlSelect:[],
      rules: {
        clientId: [
          { required: true, message: "请选择", trigger: ["change", "bulr"] }
        ],
        componentId: [
          { required: true, message: "请选择", trigger: ["change", "bulr"] }
        ],
        scheduleId: [
          { required: true, message: "请选择", trigger: ["change", "bulr"] }
        ],
        serviceId: [
          { required: true, message: "请输入", trigger: ["change", "bulr"] }
        ],
        materielId: [
          { required: true, message: "请选择", trigger: ["change", "bulr"] }
        ],
        centerControlId: [
          { required: true, message: "请选择", trigger: ["change", "bulr"] }
        ],
        operationControlId: [
          { required: true, message: "请选择", trigger: ["change", "bulr"] }
        ],
      },
    };
  },
  computed: {},
  created() {
    // console.log('this.id', this.id)
    this.ruleForm.id = this.id
    this.getResponsibleRemoveDetail()
  },
  mounted() {

  },
  computed: {},
  methods: {
    //获取删除详情
    getResponsibleRemoveDetail() {
      this.loading = true
      responsibleRemoveDetail(this.id).then(res => {
        this.loading = false
        this.clientSelect = res.result.clientSelect
        this.componentSelect = res.result.componentSelect
        this.materielSelect = res.result.materielSelect
        this.scheduleSelect = res.result.scheduleSelect
        this.serviceSelect = res.result.serviceSelect
        this.centerControlSelect = res.result.centerControlSelect
        this.operationControlSelect = res.result.operationControlSelect
      })
    },
    //取消
    handleClose(formName) {
      this.$emit("update:visible", false);
    },
    submitForm(formName) {
      console.log(this.ruleForm);
      //创建确定
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.AgreeLoading = true
          var data = {
            ...this.ruleForm
          }
          deleteResponsible(data).then(res => {
            setTimeout(() => {
              this.handleClose()
              this.$message.success('删除成功')
              this.$emit('success')
              this.AgreeLoading = false
            }, 1000);
          }).finally(() => {
            this.AgreeLoading = false
          })
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  }
};
</script>
<style lang="scss" scoped>
.ex-diolog {
  ::v-deep .ex--dialog--footer {
    border: none !important;
    padding: 0 !important;
  }

  ::v-deep .ex--dialog--main {
    padding: 10px 20px !important;
  }
}

.main {
  padding: 20px 20px;
}

.button_box {
  display: flex;
  justify-content: center;
}

.el-select {
  width: 500px !important;
}
</style>
